<?php
// TODO Either one of the phone number fields must be provided
class AboutMeForm extends sfGuardUserProfileForm {
  
  private $user;
  
  public function configure()
  {
   unset($this['user_id'], $this['created_at'], $this['updated_at']);
    
    $this->widgetSchema['is_participant'] = new sfWidgetFormChoice(array('choices' => array(-1 => '&hellip; bitte wählen &hellip;', 1 => 'teil', 0 => 'nicht teil')));//new sfWidgetFormInputCheckbox();
    $this->validatorSchema['is_participant'] = new sfValidatorBoolean(array('required' => true), array('invalid' => 'Ungültig'));
    
    $this->validatorSchema['chapter'] = new sfValidatorString(array('required' => true), array('required' => 'Pflichtfeld'));
    
    $this->validatorSchema['invoice_street'] = new sfValidatorString(array('required' => true), array('required' => 'Pflichtfeld'));    
    $this->validatorSchema['invoice_zip_code'] = new ValidatorZipCode(array('required' => true), array('required' => 'Pflichtfeld', 'invalid' => 'Ungültig'));//new sfValidatorNumber(array('required' => true), array('required' => 'Pflichtfeld'));
    $this->validatorSchema['invoice_city'] = new sfValidatorString(array('required' => true), array('required' => 'Pflichtfeld'));

    $this->validatorSchema['first_name']->setMessage('required', 'Pflichtfeld');
    $this->validatorSchema['last_name']->setMessage('required', 'Pflichtfeld');
    $this->validatorSchema['email_address'] = new sfValidatorEmail(array('required' => true), array('required' => 'Pflichtfeld', 'invalid' => 'Ungütlig'));
    
    $this->validatorSchema['contact_phone_number'] = new ValidatorPhoneNumber(array('required' => false), array('invalid' => 'Ungültig (nur Zahlen)'));
    $this->validatorSchema['contact_mobile_number'] = new ValidatorPhoneNumber(array('required' => false), array('invalid' => 'Ungültig (nur Zahlen)'));
    
    $this->widgetSchema['state_association'] = new WidgetFormChoiceStateAssociation();
    $this->validatorSchema['state_association']->setOption('required', true);
    $this->validatorSchema['state_association']->setMessage('required', 'Pflichtfeld');
    $this->validatorSchema['state_association']->setMessage('invalid', 'Ungültig');
    
    $post_validator = new OneOfTwoValidatorSchema(array(), array(OneOfTwoValidatorSchema::OPTION_WIDGET_A => 'contact_phone_number', OneOfTwoValidatorSchema::OPTION_WIDGET_B => 'contact_mobile_number'), array('invalid' => 'Bitte gebe mindestens eine Telefonnummer an.'));
    $this->mergePostValidator($post_validator);
    
  }
  
  protected function doBind(array $values) {
    parent::doBind($values);
    
    foreach($this->values as $key => $value) {
      if($this->getObject()->contains($key)) {
        $this->getObject()->set($key, $value);
      }
    }
  }
}